﻿using System.Collections.Generic;

namespace Quail.DbLogger.Task
{
    public class StoreNetworkTraffic : QuailDbLoggerEntry
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="StoreNetworkTraffic"/> class.
        /// </summary>
        /// <param name="testrunid">the test run id</param>
        /// <param name="url">The current url.</param>
        /// <param name="remoteControlUrl">The url of the remote control host</param>
        /// <param name="urlCounter">the number of times this url is hit</param>
        /// <param name="list">The list of network traffic.</param>
        public StoreNetworkTraffic(int testrunid, string url, string remoteControlUrl, int urlCounter, int msUntilReady, List<QuailServices.QuailDataServiceReference.NetworkTrafficData> list)
        {
            TestRunId = testrunid;
            RemoteControlUrl = remoteControlUrl;
            Url = url;
            UrlCounter = urlCounter;
            MsUntilReady = msUntilReady;
            Traffic = list;
        }

        private List<QuailServices.QuailDataServiceReference.NetworkTrafficData> Traffic { get; set; }

        private string RemoteControlUrl { get; set; }

        private string Url { get; set; }

        private int TestRunId { get; set; }

        private int UrlCounter { get; set; }

        private int MsUntilReady { get; set; }

        /// <summary>
        /// Stores the network traffic
        /// </summary>
        /// <param name="dataContext">the context to use</param>
        public override void Store(QuailServices.QuailDataServiceReference.QuailDataServiceClient dataContext)
        {
            dataContext.InsertNetworkTrafficUrl(TestRunId, Url, UrlCounter, RemoteControlUrl, MsUntilReady, Traffic.ToArray());
        }

        /// <summary>
        /// Returns a string representation of the entry for logging purposes
        /// </summary>
        /// <returns>A log string</returns>
        public override string GetLogDetail()
        {
            return string.Format("StoreMonitorLogEntry({0},{1},{2},{3},{4},...)", TestRunId, Url, UrlCounter, RemoteControlUrl, MsUntilReady);
        }
    }
}
